<?php
/*
 *账单
*/
namespace App\Http\Controllers;

use App\Service\BillService;
use App\Validation\BillValidation;

class BillController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
    public function indexAction()
    {
    	$this->getUser();

    	$raw = $this->validation(new BillValidation, $this->request->getJsonRawBody());

		$data = BillService::getList($raw);
		$d = [];
		foreach ($data as $key => $value) {
			$d[$key] = $value;
			//判断缩略图是否有图且url是否完整
			$d[$key]->doc = $value->doc ? $this->getFullUrl($value->doc, FALSE, $this->config->imgurl) : $this->config->imgurl . '/uploads/default.png';
		}
		$count = BillService::getList($raw, TRUE);

		$assign = [
			'total' => (int)$count,
			'list'  => $d
		];

		return $this->echoJson($assign);
    }
	
	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
    public function detailAction()
    {
    	$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = BillService::getInfo($id);

		return  $this->echoJson($data);
    }
	
}
